<?php declare(strict_types=1);


namespace App\Dao;


use App\Model\FileUploadTemp;
use Swoole\Exception;

class FileUploadTempDao extends BaseDao
{
    private $model = FileUploadTemp::class;

    /** @var string 文件状态:临时文件 */
    public const STATUS_TEMP = 'temp';
    /** @var string 文件状态:使用中 */
    public const STATUS_IN_USE = 'in_use';
    /** @var string 文件状态:已删除 */
    public const STATUS_DELETED = 'deleted';

    /**
     * 修改
     * @param $model
     * @param $params
     * @return \App\Model\FileUploadTemp
     */
    public function save($model, $params)
    {
        return $this->saveOne($model, $params);
    }

    /**
     * @param $model
     * @return \App\Model\Model|mixed|\App\Model\FileUploadTemp
     */
    public function inUse($model)
    {
        return $this->saveOne($model,['status' => self::STATUS_IN_USE]);
    }
    /**
     * 插入一条数据
     * @param $params
     * @return FileUploadTemp
     */
    public function insert($params): \App\Model\FileUploadTemp
    {
        $params['status'] = self::STATUS_TEMP;
        return $this->saveOne((new $this->model), $params);
    }

    /**
     * 用hash查找资源数据
     * @param $hash
     * @return \Hyperf\Database\Model\Builder|\Hyperf\Database\Model\Model|object|null|FileUploadTemp
     */
    public function getModel($hash)
    {
        return FileUploadTemp::query()->where('hash', $hash)->first();

    }
}